function getLocalStorageFromPage() {
  return new Promise((resolve) => {
    // 发送消息给网页
    window.postMessage(
      {
        type: 'GET_LOCALSTORAGE',
        payload: [
          { key: 'token' },
          { key: 'user_id' }
        ]
      },
      '*' // 目标 Origin，建议替换为目标网站的域名
    );
    // 监听网页的响应
    window.addEventListener('message', (event) => {
      if (event.data.type === 'LOCALSTORAGE_RESPONSE') {
        resolve(event.data.payload);
      }
    });
  });
}

getLocalStorageFromPage().then((result) => {
  chrome.storage.local.set(result).then(() => {
    console.log('Multiple data items stored successfully');
    chrome.runtime.sendMessage({action: 'SET_STORAGE',data: result})
  },(err) => {
    console.error('Error storing data:', err);
  })
});